from django.test import RequestFactory
from django.test import TestCase
from django.urls import reverse
from rest_framework import status
from rest_framework.test import APIRequestFactory

from tsl_backend.fgr_api.views.views import OrderViewSet

class OrderViewSetTestCase(TestCase):
    def setUp(self):
        self.factory = APIRequestFactory()
        self.view = OrderViewSet.as_view({'get': 'list'})
        self.url = reverse('order-list')

    def test_list_orders(self):
        request = self.factory.get(self.url, {'query': 'test'})
        response = self.view(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['name'], self.order.name)
        self.assertEqual(response.data[0]['amount'], self.order.amount)